import { useEffect, useState } from "react";
import axios from "axios";
import _ from "lodash";

export const useComment = () => {
  const [commentList, setcommentList] = useState([]);
  useEffect(() => {
    // 请求数据
    async function getList() {
      const res = await axios.get("http://localhost:3001/list");
      setcommentList(_.orderBy(res.data, ["like"], ["desc"]));
    }
    getList();
  }, []);

  return {
    commentList,
    setcommentList
  };
};
